<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>实验室助理工作管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/bootstrap.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/materialdesignicons.min.css}">
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/css/style.min.css}">
    <!--对话框-->
    <link rel="stylesheet" th:href="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.css}">
</head>
<body>

<!--页面主要内容-->
<div class="row">
    <div class="col-lg-12">
        <div class="card">
            <div class="card-header"><h4>面试信息列表</h4></div>
            <div class="card-header">
                <div class="form-group">
                    <div class="row">
                        <div class="col-xs-10">
                            <form class="form-inline" action="" >
                                <div class="form-group">
                                    <label class="sr-only" for="example-if-email">搜索</label>
                                    <input class="form-control" type="text" id="example-if-email" name="name" placeholder="search..">
                                </div>
                                <div class="form-group">
                                    <button class="btn btn-default" type="submit">搜索</button>
                                </div>
                            </form>
                        </div>
                        <div class="col-xs-1">
                            <a class="btn btn-yellow m-r-5" href="/toAudition"><i class="mdi mdi-refresh"></i>刷新</a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>面试编号</th>
                        <th>学号</th>
                        <th>姓名</th>
                        <th>岗位名称</th>
                        <th>面试成绩</th>
                        <th>是否录取</th>
                        <th>是否录入信息</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="tb_teacher">
                    </tbody>
                </table>
            </div>

            <!-- 模态框(审核) -->
            <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel">审核面试信息</h4>
                        </div>
                        <div class="modal-body">

                            <!--页面主要内容-->
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="card">
                                        <div class="card-body">
                                            <form action=""  class="row" id="userForm" name="myform">
                                                <input id="auditionId" type="text" hidden>
                                                <input id="stuId1" type="text" hidden>
                                                <div class="form-group col-md-12">
                                                    <label for="interviewResults">面试成绩</label>
                                                    <input type="text" class="form-control" id="interviewResults" name="interviewResults" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label>审核报名信息</label>
                                                    <div class="example-box">
                                                        <label class="lyear-radio radio-inline radio-primary">
                                                            <input type="radio" name="isSuccess" value="1" checked><span>同意录取</span>
                                                        </label>
                                                        <label class="lyear-radio radio-inline radio-primary">
                                                            <input type="radio" name="isSuccess" value="0" ><span>不同意录取</span>
                                                        </label>
                                                    </div>
                                                </div>
                                            </form>

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--End 页面主要内容-->
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" onclick="modify()">提交</button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- 模态框(录入信息页面) -->
            <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="myModalLabel2">录入助理信息</h4>
                        </div>
                        <div class="modal-body">

                            <!--页面主要内容-->
                            <div class="row">
                                <div class="col-lg-12">
                                    <div class="card">
                                        <div class="card-body">
                                            <form action=""  class="row" id="userForm2" name="myform2">
                                                <div class="form-group col-md-12">
                                                    <label for="assistantId">助理编号</label>
                                                    <input type="text" class="form-control" id="assistantId" name="assistantId" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="stuId">学号</label>
                                                    <input type="text" class="form-control" id="stuId" name="stuId" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="stuName">姓名</label>
                                                    <input type="text" class="form-control" id="stuName" name="stuName" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="password">密码</label>
                                                    <input type="password" class="form-control" id="password" name="password" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="major">专业</label>
                                                    <input type="text" class="form-control" id="major" name="major" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="college">学院</label>
                                                    <input type="text" class="form-control" id="college" name="college" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="aclass">班级</label>
                                                    <input type="text" class="form-control" id="aclass" name="aclass" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="grade">年级</label>
                                                    <input type="text" class="form-control" id="grade" name="grade" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="phone">手机号</label>
                                                    <input type="text" class="form-control" id="phone" name="phone" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="phone">邮箱</label>
                                                    <input type="text" class="form-control" id="mailbox" name="mailbox" value="" placeholder="" required/>
                                                </div>
                                                <div class="form-group col-md-12">
                                                    <label for="phone">所属实验室</label>
                                                    <input type="text" class="form-control" id="labName" name="labName" value="" placeholder="" required/>
                                                </div>
                                            </form>

                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!--End 页面主要内容-->
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                            <button type="button" class="btn btn-primary" onclick="modify2()">提交</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--End 页面主要内容-->

<script type="text/javascript" th:src="@{/js/jquery-3.6.0.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/bootstrap.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/perfect-scrollbar.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/main.min.js}"></script>
<!--消息提示-->
<script th:src="@{/Light-Year-Admin/js/bootstrap-notify.min.js}"></script>
<script type="text/javascript" th:src="@{/Light-Year-Admin/js/lightyear.js}"></script>
<!--对话框-->
<script th:src="@{/Light-Year-Admin/js/jconfirm/jquery-confirm.min.js}"></script>

<script type="text/javascript">

    $(function () {
        // 查询所有数据
        getLab();
    });

    // 查询所有数据
    function getLab() {
        $.ajax({
                type: "GET",
                url: "/audition/findAll",
                contentType: 'application/json;charset=utf-8', //设置请求头信息
                dataType: "json",
                success: function (result) {
                    let html = "";
                    //遍历结果集result,
                    let isSuccessStr = '';  // 是否成功录取(1录取、0没录取)
                    let interviewResults = ''; // 面试成绩
                    let isInputStr = '';  // 是否录入信息(1录入)
                    for(let i = 0;i<result.length;i++){
                        if (result[i].isSuccess == '1'){
                            isSuccessStr = '已录取';
                        }else if(result[i].isSuccess == '0'){
                            isSuccessStr = '未录取';
                        }else {
                            isSuccessStr = '未审核';
                        }


                        if (result[i].interviewResults == null){
                            interviewResults = '无';
                        }else {
                            interviewResults = result[i].interviewResults+'分';
                        }

                        if (result[i].isInput == '1'){
                            isInputStr = '已录入';
                        }else {
                            isInputStr = '未录入';
                        }

                        html += "<tr>"+
                            "<td>"+result[i].auditionId+"</td>"+
                            "<td>"+result[i].stuId+"</td>"+
                            '<td>'+result[i].stuName+"</td>"+
                            "<td>"+result[i].workName+"</td>"+
                            "<td>"+interviewResults+"</td>"+
                            "<td>"+isSuccessStr+"</td>"+
                            "<td>"+isInputStr+"</td>"+
                            '<td>'+'<a class="btn btn-info btn-sm" role="button" href="javascript:edit(\''+result[i].auditionId+'\',\''+result[i].stuId+'\')"><i class="mdi mdi-pencil"></i>审核'+
                            '</a>&nbsp;&nbsp;&nbsp;<a class="btn btn-primary btn-sm" role="button" href="javascript:add(\''+result[i].stuId+'\')"><i class="mdi mdi-content-paste"></i>录入信息'+
                            '</a>&nbsp;&nbsp;&nbsp;<a class="btn btn-danger btn-sm" role="button" href="javascript:del(\''+result[i].auditionId+'\')"><i class="mdi mdi-close-circle-outline"></i>删除</a>'+'</td>'
                            +"</tr>";
                    }
                    //将html标签拼接在html中
                    $("#tb_teacher").html(html);

                }
            }
        )
    }

    // 删除
    function del(labId) {
        $.confirm({
            title: '提示框',
            content: '是否删除？',
            buttons: {
                confirm: {
                    text: '确认',
                    action: function(){
                        lightyear.loading('show');  // 显示
                        $.ajax({
                            type: "GET",
                            url: "/lab/delete?labId=" + labId,
                            contentType: 'application/json;charset=utf-8', //设置请求头信息
                            dataType: "json",
                            success: function (res) {
                                if (res.code == 200) {
                                    setTimeout(function () {
                                        lightyear.loading('hide');
                                        lightyear.notify('删除成功', 'danger', 5000, 'mdi mdi-emoticon-happy', 'top', 'center');
                                        //window.location.href = "/toLab";
                                        getLab()
                                    }, 600);
                                }
                            },
                            error: function (result) {
                                errorToast(result.msg);
                            }
                        });
                    }
                },
                cancel: {
                    text: '关闭',
                    action: function(){

                    }
                },
            }
        });
    }

    // 审核
    function modify() {
        //获取模态框数据
        var auditionId = $("#auditionId").val();
        var stuId = $("#stuId1").val();
        var interviewResults = $("#interviewResults").val();
        // 获取单选框的值
        var isSuccess = $('input[type=radio][name=isSuccess]:checked').val();

        var param = {auditionId: auditionId, stuId:stuId,interviewResults: interviewResults, isSuccess: isSuccess};

        $.ajax({
            url: "/audition/update",
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(param),
            success: function (data) {
                if(data.code == 200 ){
                    reset();
                    $('#myModal').modal('hide');
                    lightyear.notify('审核成功', 'success', 800, 'mdi mdi-emoticon-happy', 'top', 'center');
                    getLab();
                }else{
                    alert("失败")
                }
            }
        });
    }

    // 打开(审核)页面
    function edit(auditionId,stuId) {
        //向模态框中传值
        $('#auditionId').val(auditionId);
        $('#stuId1').val(stuId);
        $('#myModal').modal('show');
    }

    // 打开(录入信息)页面
    function add(stuId) {
        reset2()
        $.ajax({
            url: "/student2/findOne/" + stuId,
            type: "GET",
            success: function (result) {
                console.log(result)
                if (result.data) {
                    //向模态框中传值
                    $('#stuId').val(result.data.stuId);
                    $('#stuName').val(result.data.stuName);
                    $('#password').val(result.data.password);
                    $('#major').val(result.data.major);
                    $('#college').val(result.data.college);
                    $('#aclass').val(result.data.aclass);
                    $('#grade').val(result.data.grade);
                    $('#phone').val(result.data.phone);
                    $('#mailbox').val(result.data.mailbox);
                } else {
                    alert(result.data.message);
                }
            }
        });
        $('#myModal2').modal('show');
    }

    // 录入信息
    function modify2() {
        //获取模态框数据
        let assistantId = $('#assistantId').val();
        let stuId = $('#stuId').val();
        let stuName = $('#stuName').val();
        let password = $('#password').val();
        let major = $('#major').val();
        let college = $('#college').val();
        let aclass = $('#aclass').val();
        let grade = $('#grade').val();
        let phone = $('#phone').val();
        let mailbox = $('#mailbox').val();
        let labName = $('#labName').val();

        var param = {assistantId: assistantId, stuId: stuId, stuName: stuName,password:password,major:major,
                    college:college,aclass:aclass,grade:grade,phone:phone,mailbox:mailbox,labName:labName};

        $.ajax({
            url: "/assistant/add",
            type: "POST",
            contentType: "application/json",
            dataType: "json",
            data: JSON.stringify(param),
            success: function (data) {
                if(data.code == 200 ){
                    reset();
                    $('#myModal2').modal('hide');
                    lightyear.notify('信息录入成功', 'success', 800, 'mdi mdi-emoticon-happy', 'top', 'center');
                    getLab();
                }else{
                    alert("失败")
                }
            }
        });
    }

    // 清空模态框（审核）
    function reset() {
        $('#auditionId').val("");
        $("#interviewResults").val("");
    }

    // 清空模态框（录入信息）
    function reset2() {
        $('#assistantId').val("");
        $('#stuId').val("");
        $('#stuName').val("");
        $('#password').val("");
        $('#major').val("");
        $('#college').val("");
        $('#aclass').val("");
        $('#grade').val("");
        $('#phone').val("");
        $('#mailbox').val("");
        $('#labName').val("");
    }

</script>
</body>
</html>